<?php

namespace app\api\controller;

use app\api\BaseController;
use app\api\middleware\Auth;
use app\api\validate\NoteValidate;
use app\load\loadServices\NoteServices;
use think\Exception;

/**
 * 企业公告
 */
class Note extends BaseController
{

    /**
     * 免登录方法
     * 控制器中间件 [登录 不需要鉴权]
     * @var array
     */
    protected $middleware = [
        Auth::class => ['except' => []]
    ];


    /**
     * 列表
     * @return void
     */
    public function  list()
    {

        $input = input();
        try {
            $where[] = ['status', '=', 1];
            if (!empty($input['cate_id'])) {
                $where[] = ['cate_id', '=', $input['cate_id']];
            }
            $result = NoteServices::Notes()->list($where, 'id,title,content,create_time,admin_id as admin_name');
            $this->apiSuccess('请求成功', $result);
        } catch (Exception $e) {
            $this->apiError($e->getMessage());
        }
    }

    /**
     * 列表详情
     * @return void
     */
    public function info()
    {

        $input = input();
        try {
            validate(NoteValidate::class)->scene('info')->check($input);
            $result = NoteServices::Notes()->info(['id' => $input['id']], 'id,title,content,create_time,admin_id,cate_id');
            $this->apiSuccess('请求成功', $result);
        } catch (Exception $e) {
            $this->apiError($e->getMessage());
        }
    }


    /**
     * 公告类型
     * @return void
     */
    public function list_type()
    {

        try {
            $result = NoteServices::Notes()->listType([], 'id,title,create_time');
            $this->apiSuccess('请求成功', $result);
        } catch (Exception $e) {
            $this->apiError($e->getMessage());
        }
    }


}